home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / GAF200B.ZIP / DOC / TUTORIAL.DOC < prev   
Encoding:
Text File  |  1994-10-21  |  16.9 KB  |  406 lines

  1. Introduction
  2.   This document explains how to build a control simulation under
  3.   GAF.  A brief description of basic concept and steps to build a
  4.   simulation is presented.  Then, a simple example of water heater
  5.   control is used to explore the basics of GAF.
  6.  
  7. What is a segment
  8.   A segment is a text file contains:
  9.   · configuration information
  10.   · variable declarations (IN, OUT, INOUT, and LOCAL)
  11.   · symbol (fuzzy membership set) declarations
  12.   · condition to enable the segment
  13.   · initialization
  14.   · reset
  15.   · pre-processing
  16.   · post-processing
  17.   · fuzzy rules
  18.  
  19.   Just like dividing the system into several manageable portions,
  20.   GAF allows a control system to be divided into segments.  For
  21.   example, a simulated control environment under GAF may have these
  22.   different segments:
  23.   · control segment(s)
  24.   · reference calculation and supporting segment(s)
  25.   · simulation (or feedback) segment(s)
  26.   · evaluation segment
  27.   The feedback and evaluation segments are used for simulation and
  28.   adaptation.
  29.  
  30. Segment Construction
  31.   To construct a segment is quite similar to construct a simple
  32.   program.  Please refer to FCL.DOC for detail syntax and *.gaf,
  33.   *.fbk, *.sim, and *.evl files for examples.  Note that these
  34.   steps can be in any order to your convience.  These steps are:
  35.  
  36.   1.  Define variables
  37.     All variables must be declared before they can be used either
  38.     by fuzzy rules or any statements in a segment.  There are four
  39.     types of variables: IN, OUT, INOUT, and LOCAL.
  40.  
  41.     IN Variables
  42.       IN variables are used as "references" in this segment.  IN
  43.       variables must be in one of the categories:
  44.         · calculated by other segment (as OUT or INOUT)
  45.         · an input from real world, i.e. a sensor, in the simulation this
  46.           input may be an OUT from a feedback segment.
  47.         · application constants, can be modified through interactive
  48.           interface during simulation
  49.  
  50.     OUT variables
  51.       OUT variables are calculated outputs by this segment.  OUT
  52.       variables are either:
  53.         · an output signal to a real world device
  54.         · be used by other segment as IN variables
  55.         · for diagnostic purpose
  56.         · evaluation result
  57.       Note that for each output variable, there must be only one
  58.       segment declares it as an OUT or INOUT variable.  If more
  59.       than one segment declares an output variable as OUT or INOUT,
  60.       the result is undefined.
  61.  
  62.     INOUT variables
  63.       INOUT variables are both referenced and modified by this
  64.       segment, i.e., it is the combination of both IN and OUT
  65.       variables.  Normally INOUT variables are referenced by this
  66.       segment and other segments.
  67.  
  68.     All of the IN, OUT, and INOUT variables are visible to other
  69.     segments, i.e. other segments can use this segment's OUT as its
  70.     IN.
  71.  
  72.     LOCAL variables
  73.       LOCAL variables are local to this segment.  Normally, local
  74.       variables are used to store temporary values so it can be
  75.       used by fuzzy rules or other statements within the segment.
  76.  
  77.  
  78.   2. Define fuzzy membership
  79.     The second step would be define the fuzzy membership set.  GAF
  80.     uses four points for each set.  In general, fuzzy sets should
  81.     be defined for each variable, either in out or local, that is
  82.     used in the fuzzy rules.  For example, as described in the
  83.     following figure.  A simple way to define membership sets for a
  84.     variable is to equaly divide the range of the variable into six
  85.     to obtain five sets - very low (VL), low (LO), medium (M), high
  86.     (HI), and very high (VH).
  87.  
  88.        -----     -     -     -     -----
  89.             \   / \   / \   / \   /
  90.              \ /   \ /   \ /   \ /
  91.               X     X     X     X
  92.              / \   / \   / \   / \
  93.             /   \ /   \ /   \ /   \
  94.      +-----+-----+-----+-----+-----+-----+
  95.      -1  -0.67 -0.33   0    0.33  0.67   1
  96.      | very low  |  medium   | very high |
  97.            |    low    |   high    |
  98.  
  99.     As the above diagram shows these five membership sets are
  100.     symmatrically divided.  Then, use these membership sets for the
  101.     starting point.
  102.     
  103.         SYMBOL very_low  (-1.00, -1.00, -0.67, -0.33, 1.0)
  104.         SYMBOL low       (-0.67, -0.33, -0.33   0,    1.0)
  105.         SYMBOL medium    (-0.33,  0,     0,     0.33, 1.0)
  106.         SYMBOL high      ( 0,     0.33,  0.33,  0.67, 1.0)
  107.         SYMBOL very_high ( 0.33,  0.67,  1,     1,    1.0)
  108.  
  109.  
  110.   3. Translate ideas into fuzzy rules
  111.     Defining fuzzy rules is quite straight forward.  Basically,
  112.     this step is simply converting an imprecise idea of how things
  113.     should work into fuzzy rules.  For example, based on common
  114.     sense to control a water heater, a simple rule may be like:
  115.       "if water usage is heavy and water is cold,
  116.       then the gas fuel valve to heat the tank must be full open"
  117.     This idea can turn into a rule like:
  118.       IF water_usage IS heavy AND water IS cold
  119.       THEN fuel_valve IS full_open
  120.     Where water_usage and water are IN variables, fuel_valve is an
  121.     OUT variable; heavy, cold, and full_open are membership sets
  122.     defined for corresponding variables.  Note that all variables
  123.     that are part of "THEN" statement must be declared as OUT or
  124.     INOUT.
  125.     
  126.     Please refer to step 6 for more information.
  127.  
  128.  
  129.  
  130.   4. Initializes the segment
  131.     Next step is to define what do you want the segment to be
  132.     initialized.  In general, the initialization of a segment is to
  133.     initialize all outputs (OUT and INOUT variables) and its local
  134.     variables.  The initialization will be executed when the system
  135.     "comes up" (i.e., the first time it runs the segment) or
  136.     requested from user interactive interface.  The initialization
  137.     formulas and other processing formulas are arranged like this:
  138.  
  139.         what's in the text      remarks
  140.         -------------------     ----------------------------------------
  141.         INITIALIZATION          must have this key word
  142.                 ... ;             statements for initialization
  143.                                   each statement must end with ';'
  144.         RESET                   optional key word for reset processing
  145.                 ... ;           optional statements for reset processing
  146.         PRE_PROCESSING          optional key word for pre-processing
  147.                 ... ;           optional statements for pre-processing
  148.         POST_PROCESSING         optional key word for post-processing
  149.                 ... ;           optional statements for post-processing
  150.         END;                    must have this key word (with ';')
  151.  
  152.     Note that INITIALIZATION must be the first statemant and END
  153.     must be the last statement.  For example, for the above water
  154.     heat control, the segment should initialize the fuel_valve to
  155.     close.
  156.     
  157.         INITIALIZATION
  158.                 fuel_valve = 0;
  159.         PRE_PROCESSING
  160.                 ...
  161.         END;
  162.  
  163.  
  164.   5. Reset processing
  165.     Similar to initialization, the reset processing is to reset the
  166.     segment when the segment is disabled.  The reset processing is
  167.     only necessary when it is different from the initialization.
  168.  
  169.  
  170.   6. Pre-processing and post-processing
  171.     The pre-processing is a set of statements to be calculated
  172.     before the fuzzy rules are inferenced.  The post-processing is
  173.     a set of statements to be calculated after the fuzzy rules are
  174.     inferenced.  The formulas can be used for calculating
  175.     references or other simple mathematical models.  Pre-processing
  176.     is calculated before any fuzzy rule been evaluated, so the
  177.     results of these formulas may be used by fuzyy rules to
  178.     inference the result.
  179.  
  180.  
  181.   7. Segment enable condition
  182.     Now, it's time to decide how and when should this segment be
  183.     enabled.  The enable condition determines whether the segment
  184.     shoud run or not.  If enable condition is not specified GAF
  185.     treats the segment as enabled all the time.
  186.  
  187.  
  188.  
  189. Example: Water Heater Temperature Control
  190.  
  191.   Let's use a simple water heater control to illustrate these steps
  192.   in constructing a control segment.  First, let's explain the
  193.   simple device that we are going to control.
  194.  
  195.   The water heater
  196.     The following diagram shows the physical layout of the water
  197.     heater.
  198.  
  199.                      temperature sensor
  200.                              !
  201.                              !
  202.                      /-------!-------\     valve
  203.             high     |       !      <=======x======= water in
  204.             sensor----x      !       |
  205.                      |       !       |
  206.                      |       !       |
  207.                      |       !       |
  208.                      |       !       |
  209.                      |       !       |
  210.                      |       !       |
  211.                      |       !       |
  212.                      |       !       |   low
  213.                      |       !      x----sensor
  214.      water   valve   |               |
  215.      out <=====x======               |
  216.                      \---------------/
  217.                          ^^^^^^^^^    burner
  218.                              !
  219.                              !<======x=======fuel
  220.                                    valve
  221.     
  222.  
  223.     As shown in the diagram, these are the major devices for the
  224.     water heater and can be used by the controller to control the
  225.     water temperature.
  226.       2 water valves: in & out
  227.       2 water sensors: high & low
  228.       1 water temperature sensor
  229.       1 fuel valve
  230.     
  231.     Let's also assume that the heater can heat a full tank of water
  232.     up one degree per second with max gas fuel.  The water tank can
  233.     be drained in 100 seconds with full-open water out valve.
  234.     
  235.     To simplify the problem, let's split the controller into two
  236.     part: a water temperature control and a water volume control.
  237.     The reason, besides cover this example in few pages, is to
  238.     isolate the temperature controller from the water controller.
  239.     So, inside the temperature controller we can assume that the
  240.     water volume is a constant.
  241.     
  242.     
  243.   Step 1: Define variables
  244.     Since we are only controling the water temperature, it is quite
  245.     easy to identify the output of the controller, i.e., the fuel
  246.     valve.  The inputs to this controller are: the water
  247.     consumption (from the valve of water out), the water
  248.     temperature from the sensor.  Also, there should be a target
  249.     temperature as an input to this controller.  After identify
  250.     these variables, now we can find out their range and declare
  251.     these variables.
  252.       IN Target_Temp (32, 212)    ! target temperature
  253.       IN Temperature (32, 212)    ! measured temperature
  254.       IN Water_out (0, 1)       ! 0 - 1 input from the water out valve
  255.       OUT Gas_valve (0, 10)     ! 0 - 10 volts output to the fuel valve
  256.     
  257.     
  258.     
  259.     
  260.   Step 2: Define Pre-processing and Initialization
  261.     Because we only care about the temperature error, which is the
  262.     difference between the reference and the measured water
  263.     temperature.  So, we can use the pre-processing to calculate
  264.     the temperature error before inference the fuzzy rules.  In
  265.     order to do this, a new local variable has to be put in:
  266.       LOCAL Temp_error (-180, 180)
  267.     Then the pre-processing and initialization is:
  268.       INITIALIZATION
  269.         Gas_valve = 0;    ! turn off the valve
  270.         Temp_error = 0;   !
  271.       PRE_PROCESSING
  272.         Temp_error =  Temperature - Target_Temp ;
  273.       END;
  274.   
  275.   
  276.   
  277.   
  278.   Step 3: Define Fuzzy Membership
  279.     Let's start defining membership set by using the simple method
  280.     discussed.  Note that for the water consumption, and gas valve
  281.     only the right half (> 0) is used.
  282.     
  283.     The Water_out  variable divided into 5 bands, i.e., very heavy,
  284.     heavy, medium, light, and zero comsumption.  The result would
  285.     be:
  286.     
  287.       -     -     -     -     -------
  288.        \   / \   / \   / \   /
  289.         \ /   \ /   \ /   \ /
  290.          X     X     X     X
  291.         / \   / \   / \   / \
  292.        /   \ /   \ /   \ /   \
  293.       +-----+-----+-----+-----+-----+
  294.       0    0.2   0.4   0.6   0.8   1.0
  295.       
  296.       !                               below     low    high   above  truth
  297.       SYMBOL Zero      OF Water_out (   0.0,    0.0,    0.0,   0.2,    1.0)
  298.       SYMBOL Light     OF Water_out (   0.0,    0.2,    0.2,   0.4,    1.0)
  299.       SYMBOL Medium    OF Water_out (   0.2,    0.4,    0.4,   0.6,    1.0)
  300.       SYMBOL Heavy     OF Water_out (   0.4,    0.6,    0.6,   0.8,    1.0)
  301.       SYMBOL VeryHeavy OF Water_out (   0.6,    0.8,    1.0,   1.0,    1.0)
  302.     
  303.     The Temp_error variable is divided into these five membership
  304.     sets (with extended VeryHot and VeryCold):
  305.     
  306.         -------     -     -     -     -----
  307.                \   / \   / \   / \   /
  308.                 \ /   \ /   \ /   \ /
  309.                  X     X     X     X
  310.                 / \   / \   / \   / \
  311.                /   \ /   \ /   \ /   \
  312.         +-..--+-----+-----+-----+-----+--..-+
  313.       -180   -40   -20    0    20    40    180
  314.       
  315.       !                               below     low    high   above   truth
  316.       SYMBOL VeryCold OF Temp_error (-180.0, -180.0,  -40.0,  -20.0,    1.0)
  317.       SYMBOL Cold     OF Temp_error ( -40.0,  -20.0,  -20.0,    0.0,    1.0)
  318.       SYMBOL OnTarget OF Temp_error ( -20.0,    0.0,    0.0,   20.0,    1.0)
  319.       SYMBOL Hot      OF Temp_error (   0.0,   20.0,   20.0,   40.0,    1.0)
  320.       SYMBOL VeryHot  OF Temp_error (  20.0,   40.0,  180.0,  180.0,    1.0)
  321.     
  322.     
  323.     The Gas_valve variable:
  324.     
  325.       -     -     -     -     -------
  326.        \   / \   / \   / \   /
  327.         \ /   \ /   \ /   \ /
  328.          X     X     X     X
  329.         / \   / \   / \   / \
  330.        /   \ /   \ /   \ /   \
  331.       +-----+-----+-----+-----+-----+
  332.       0     2     4     6     8    10
  333.       
  334.       !                              below     low    high   above   truth
  335.       SYMBOL Off      OF Gas_valve (   0.0,    0.0,    0.0,    2.0,   1.0)
  336.       SYMBOL VeryLow  OF Gas_valve (   0.0,    2.0,    2.0,    4.0,   1.0)
  337.       SYMBOL Low      OF Gas_valve (   2.0,    4.0,    4.0,    6.0,   1.0)
  338.       SYMBOL High     OF Gas_valve (   4.0,    6.0,    6.0,    8.0,   1.0)
  339.       SYMBOL VeryHigh OF Gas_valve (   6.0,    8.0,   10.0,   10.0,   1.0)
  340.     
  341.     
  342.     
  343.     
  344.   Step 4: Translate Ideas Into Fuzzy Rules
  345.     Using common sense to implement rules, such as turn this idea
  346.       if the water consumption is very heavy and the water is very
  347.       cold then full open the gas fuel valve
  348.     into a rule
  349.       IF Water_out IS VeryHeavy AND Temp_error IS VeryCold
  350.       THEN Gas_valve IS VeryHigh
  351.     
  352.     There is an easy approach for this simple controller - by
  353.     filling a table.  As shown in the following table, this rule's
  354.     output VeryHigh is in the top left cell.  The rest of the table
  355.     can be filled in based on this kind of common ideas.
  356.     
  357.                  VeryHeav  Heavy     Medium    Light     Zero
  358.                  --------  --------  --------  --------  --------
  359.      VeryCold    VeryHigh  VeryHigh  VeryHigh  VeryHigh  VeryHigh
  360.      Cold        VeryHigh  VeryHigh  VeryHigh  High      High
  361.      OnTarget    VeryHigh  High      Low       VeryLow   Off
  362.      Hot         High      Low       VeryLow   Off       Off
  363.      VeryHot     Low       VeryLow   Off       Off       Off
  364.     
  365.     
  366.     Note that some may argue that the "table filling" approach can
  367.     be applied not just simple controls but also complex controls
  368.     by pairing two inputs and one output.  But a system built with
  369.     this approach (without optimization) may require intense CPU
  370.     power and contain extremely complicated rule set.
  371.   
  372.   
  373.   
  374.   
  375.   Step 5: Segment Enable Condition
  376.     In order to avoid unnecessary sensitive reaction from the
  377.     controller, a hysteresis null band can be put in to enable or
  378.     disable the control segment.   As in the example file
  379.     heattank.sim, the output variable Heating is calculated based
  380.     on a hysteresis null band.  So, we can add an ENABLE condition
  381.     to achieve this:
  382.       ENABLE = Heating;
  383.     This will disable the segment within the hysteresis null band.
  384.     When the segment is disabled we want shut off the output
  385.     Gas_valve, because this is identical to the initialization, so
  386.     it's not necessary to define the RESET processing.
  387.   
  388.   
  389.   
  390.   
  391.   Results
  392.     Please refer to the accompany files heattank.x01 and
  393.     heattank.x02 for the result of this excercise.
  394.     Note:
  395.     1.  The Temp_error is calculated outside this control segment.
  396.     2.  The symbol Off and VeryHigh defined for Gas_valve have special
  397.         "center" values, which define the output center value for these
  398.         fuzzy sets.
  399.     3.  The .x02 has incorporated some simplifications of the rules
  400.         (from the above rule table).
  401.   
  402.     The heattank.fbk emulates the reaction of the water tank with
  403.     simple calculation based on the input/output energy.  A few
  404.     rules are added to introduce some heat loss and non-linear
  405.     portion of the system.
  406.